package com.store.pet.petstore.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.squareup.picasso.Picasso;
import com.store.pet.petstore.R;
import com.store.pet.petstore.bean.CommodityBean;
import com.store.pet.petstore.util.DateUtil;

import java.util.List;

public class CommodityAdapter extends BaseQuickAdapter<CommodityBean.ContentBean.PetlistBean,BaseViewHolder> {

    public CommodityAdapter(int layoutResId, @Nullable List<CommodityBean.ContentBean.PetlistBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CommodityBean.ContentBean.PetlistBean item) {
        helper.setText(R.id.commodity_item_name,item.getName());  //绑定id和数据
        int status = item.getStatus();
        //根据status值设置商品状态
        if(status == 1){
            helper.setText(R.id.commodity_item_status,"商品状态：在售中");
        }else if(status == 2){
            helper.setText(R.id.commodity_item_status,"商品状态：已下单");
        }else if(status == 3){
            helper.setText(R.id.commodity_item_status,"商品状态：已发货");
        }else if(status == 4){
            helper.setText(R.id.commodity_item_status,"商品状态：已付款");
        }
        helper.setText(R.id.commodity_item_time,"发布时间："+item.getCtime().replaceAll("T"," "));  //发布时间
        helper.setText(R.id.commodity_item_price,"价格："+item.getPrice());  //价格
        ImageView imageView = helper.getView(R.id.commodity_item_img);  //根据id获取Imageview
        Picasso.with(mContext).load(item.getImg()).into(imageView);  //Picasso框架加载网络图片
        helper.addOnLongClickListener(R.id.commodity_item);
        helper.addOnClickListener(R.id.commodity_item);
    }
}
